package com.baoyouqun.controller.back;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.OrderRecordCreateCmd;
import com.baoyouqun.domain.Query.OrderRecordQuery;
import com.baoyouqun.domain.UpdateCmd.OrderRecordUpdateCmd;
import com.baoyouqun.domain.VO.OrderRecordVO;
import com.baoyouqun.service.OrderRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/back/orderRecord")
@Api(tags = "订单记录表管理接口")
public class OrderRecordController {

    @Resource
    private OrderRecordService orderRecordService;

    @PostMapping("create")
    @ApiOperation("新增订单记录表")
    public SingleResponse<OrderRecordVO> create(OrderRecordCreateCmd cmd) {
        return orderRecordService.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改订单记录表")
    public Response update(OrderRecordUpdateCmd cmd) {
        return orderRecordService.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除订单记录表")
    public Response delete(String id) {
        StpUtil.checkRole("R010000");
        orderRecordService.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询订单记录表")
    public SingleResponse<OrderRecordVO> selectById(String id) {
        return SingleResponse.of(orderRecordService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询订单记录表")
    public PageResponse<OrderRecordVO> page(OrderRecordQuery query) {
        IPage<OrderRecordVO> page = orderRecordService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}